/**********************************************************************
Compile : gcc -O3 -o unpacking unpacking.c
Usage : ./unpacking filename
**********************************************************************/

#include <stdio.h>

int main (int argc, char *argv[])
{
	FILE *fp;
	int M, N, L;

	fp = fopen (argv[1], "r");
	fread (&M, sizeof (int), 1, fp);
	fread (&N, sizeof (int), 1, fp);
	fread (&L, sizeof (int), 1, fp);

	int i, j, k, p, number;
	int pathway[8][L][N];
	char packing[L][N];

	number = 0;
	while (number < M)
	{
		fread (packing, sizeof (char), L * N, fp);
		number += 8;

		for (i = 0; i < L; i++)
		{
			for (j = 0; j < N; j++)
			{
				for (k = 0; k < 8; k++)
				{
					if (packing[i][j] & (1<<k))
						pathway[k][i][j] = 1;
					else
						pathway[k][i][j] = 0;
				}
			}
		}

		if (number > M)
			p = 8 - (number - M);
		else
			p = 8;

		for (k = 0; k < p; k++)
		{
			printf ("c candidate process\n");
			for (i = 0; i < L; i++)
			{
				for (j = 0; j < N; j++)
				{
					printf ("%d ", pathway[k][i][j]);
				}
				printf ("\n");
			}
		}
	}

	fclose (fp);
}
